package lesson25;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MyVisibility {

    int a = 10;

    int b = 20;

    private void change(){
        a = 30;
        b = a;
    }

    private void print(){
        if(b == 30 && a == 10){
            System.out.println(Thread.currentThread().getName() +": b="+b+"; a=" + a);
        }

    }

    public static void main(String[] args) {

        ExecutorService executorService = Executors.newFixedThreadPool(20);

        while (true){

            MyVisibility myVisibility = new MyVisibility();

            executorService.execute(() -> {
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                myVisibility.change();

            });

            executorService.execute(() -> {
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                myVisibility.print();

            });

        }
    }

}
